package com.quasar.hpatient.bean.home_urinevolume;

import android.text.TextUtils;

import com.quasar.hpatient.R;

import lib.quasar.context.BaseConstant;
import lib.quasar.util.LogUtil;
import lib.quasar.widget.chart.entry.Entry;

/**
 * description: 出入量
 * created by kalu on 2018/4/25 9:36
 */
public class UrinevolumeItemBean implements Entry {

    private String record_datetime = "";
    private String record_dose = "";
    private String record_type = "0";
    private String record_input = "0";
    private String record_output = "0";
    private String record_night = "0";
    private String record_name = "";

    public String getRecord_datetime() {
        return record_datetime;
    }

    public void setRecord_datetime(String record_datetime) {
        this.record_datetime = record_datetime;
    }

    public String getRecord_dose() {
        return record_dose;
    }

    public void setRecord_dose(String record_dose) {
        this.record_dose = record_dose;
    }

    public String getRecord_type() {
        return record_type;
    }

    public void setRecord_type(String record_type) {
        this.record_type = record_type;
    }

    public String getRecord_value() {
        if ("入量".equals(record_name)) {
            return record_input;
        } else if ("白天尿量".equals(record_name)) {
            return record_output;
        } else {
            return record_night;
        }
    }

    public String getRecord_input() {
        return record_input;
    }

    public void setRecord_input(String record_input) {
        this.record_input = record_input;
    }

    public String getRecord_output() {
        return record_output;
    }

    public void setRecord_output(String record_output) {
        this.record_output = record_output;
    }

    public String getRecord_night() {
        return record_night;
    }

    public void setRecord_night(String record_night) {
        this.record_night = record_night;
    }

    public String getRecord_name() {
        return record_name;
    }

    public void setRecord_name(String record_name) {
        this.record_name = record_name;
    }

    @Override
    public String getAxisX() {
        return getLogtime(true);
    }

    @Override
    public float getAxisYMax() {
        return 0;
    }

    @Override
    public float getAxisYMin() {
        return 0;
    }

    public String getLogtime(boolean onlyHour) {

        if (!TextUtils.isEmpty(record_datetime) && record_datetime.length() >=16) {
            return record_datetime.substring(onlyHour ? 11 : 0, 16);
        } else {
            return "时间错误";
        }
    }

    @Override
    public float getValue() {

        final String record_value = getRecord_value();

        try {
            return Float.parseFloat(record_value);
        } catch (Exception e) {
            return 0f;
        }
    }

    @Override
    public float[] getValues() {
        return null;
    }

    @Override
    public String getUnit() {
        return BaseConstant.NULL_STR;
    }

    public int getColor() {
        try {

            String value;
            if ("入量".equals(record_name)) {
                value = record_input;
            } else if ("白天尿量".equals(record_name)) {
                value = record_output;
            } else {
                value = record_night;
            }

            float temp = Float.parseFloat(value);
            return (temp <= 35f || temp >= 39) ? R.color.color_bg_peach : R.color.color_bg_theme;
        } catch (Exception e) {
            e.printStackTrace();
            return R.color.color_bg_theme;
        }
    }

    @Override
    public String getDate() {
        try {
            return record_datetime.substring(5, 10);
        } catch (Exception e) {
            LogUtil.e("", e.getMessage(), e);
            return record_datetime;
        }
    }

    @Override
    public String getName() {
        return record_name;
    }

    public boolean isInput() {
        return "入量".equals(record_name);
    }

    public boolean isOutput() {
        return "白天尿量".equals(record_name);
    }

    public String getKey() {
        if (!TextUtils.isEmpty(record_datetime) && record_datetime.length() != 18) {
            return record_datetime.substring(0, 11) + "00:00:00";
        } else {
            return "0000-00-00 00:00:00";
        }
    }

    public boolean isLessTime(String datetime) {

        /**
         * 如果参数字符串等于此字符串，则返回值 0；
         * 如果此字符串小于字符串参数，则返回一个小于 0 的值；
         * 如果此字符串大于字符串参数，则返回一个大于 0 的值。
         */
        return record_datetime.compareToIgnoreCase(datetime) < 0;
    }
}
